package com.hoas.quickstart.threads.chapter01.chapter01_7_3;

public class MyThread extends Thread {

    @Override
    public void run() {
        super.run();
        try {
            for (int i = 0; i < 500000; i++) {
                if (this.interrupted()) {
                    System.out.println("已经是停止状态了，我要退出了！");

    //                break并不能真正停止线程的执行，仅仅是跳出循环
    //                break;

                    throw new InterruptedException();

                }
                System.out.println("i=" + (i+1));
            }

            System.out.println("我被输出，如果此代码是for循环有继续执行，线程并未停止！");
        } catch (InterruptedException e) {

            System.out.println("进入了MyThread.java类run方法中的catch了");
            e.printStackTrace();
        }
    }
}
